﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BeeHit : MonoBehaviour {
    public static BeeHit con;

    public void Awake()
    {
        con = this;
    }

    private bool Collid;

    private CapsuleCollider2D ca;
    private Animator an;

    [Header("最大血量")]
    public float maxBlood;

    [Header("当前血量")]
    public float Blood;

    [Header("血量视图")]
    public EnemyBloodController bloodView;
    
    // Use this for initialization
    void Start()
    {
        ca = GetComponent<CapsuleCollider2D>();
        an = GetComponent<Animator>();
        Blood = maxBlood;
        bloodView.maxBlood = maxBlood;
    }

    void Update()
    {
        an.SetTrigger("Idle");
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag=="sword")
        {
            an.SetTrigger("Hit");
            Blood = Blood - Player.con.attack;
            bloodView.SetBloodValue(Blood);
            if (Blood <= 0)
            {
                Destroy(gameObject);
                EnemyBee.con.Die();
                CreatBee.con.CreatMen();
                CoinController.con.CreatCoin(gameObject.transform, 50);
            }
        }
    }
}
